package com.mysen;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.util.IOUtils;
import com.mysen.init.InitEnvProperties;
import com.mysen.init.InitLog4j;
import com.mysen.init.Initatial;

public class Application extends ApplicationObjectSupport{

    private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);

	private static List<Initatial> inits = new ArrayList<>();
	
	private static void registe(Initatial init) {
		init.init();
		inits.add(init);
	}
	
	private static ClassPathXmlApplicationContext ctx = null;
	
	public static void main(String[] args) {
		try{
			registe(InitLog4j.getInstance());
			registe(InitEnvProperties.getInstance());
			ctx = new ClassPathXmlApplicationContext(new String[]{"classpath*:/spring/applicationContext.xml"});
			ctx.start();
			for(Initatial init : inits) {
				init.init(ctx);
			}
			synchronized (Application.class) {
				while (true) {
					Application.class.wait();
				}
			}
		} catch (Throwable e){
			IOUtils.close(ctx);
			LOGGER.error("service start error!!!",e);
		}
	}

}